package com.ruoyi.model.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.model.domain.ModelTask;
import com.ruoyi.model.domain.ModelTaskLayer;
import com.ruoyi.model.domain.vo.ModelTaskVo;
import com.ruoyi.model.service.IModelTaskLayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/model/tasklayer")
public class ModelTaskLayerController extends BaseController {
    @Autowired
    private IModelTaskLayerService modelTaskLayerService;

    @PreAuthorize("@ss.hasPermi('model:tasklayer:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelTaskLayer modelTaskLayer)
    {
        startPage();
        List<ModelTaskLayer> list = modelTaskLayerService.selectModelTaskLayerList(modelTaskLayer);
        return getDataTable(list);
    }
    @GetMapping("/getNoPageList")
    public AjaxResult getNoPageList(ModelTaskLayer modelTaskLayer){
        List<ModelTaskLayer> list = modelTaskLayerService.selectModelTaskLayerList(modelTaskLayer);
        return  AjaxResult.success(list);
    }

    /**
     * 导出任务图层关联列表
     */
    @PreAuthorize("@ss.hasPermi('model:tasklayer:export')")
    @Log(title = "任务模型关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelTaskLayer modelTaskLayer)
    {
        List<ModelTaskLayer> list = modelTaskLayerService.selectModelTaskLayerList(modelTaskLayer);
        ExcelUtil<ModelTaskLayer> util = new ExcelUtil<ModelTaskLayer>(ModelTaskLayer.class);
        util.exportExcel(response, list, "任务模型关联数据");
    }

    /**
     * 获取任务图层关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:tasklayer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelTaskLayerService.selectModelTaskLayerById(id));
    }

    /**
     * 新增任务图层关联
     */
    @PreAuthorize("@ss.hasPermi('model:tasklayer:add')")
    @Log(title = "任务图层关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModelTaskLayer modelTaskLayer)
    {
        return toAjax(modelTaskLayerService.insertModelTaskLayer(modelTaskLayer));
    }

    /**
     * 修改任务图层关联
     */
    @PreAuthorize("@ss.hasPermi('model:tasklayer:edit')")
    @Log(title = "任务图层关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ModelTaskLayer modelTaskLayer)
    {
        return toAjax(modelTaskLayerService.updateModelTaskLayer(modelTaskLayer));
    }

    /**
     * 删除任务图层关联
     */
    @PreAuthorize("@ss.hasPermi('model:tasklayer:remove')")
    @Log(title = "任务图层关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelTaskLayerService.deleteModelTaskByIds(ids));
    }
}
